/**
 * ShopReactNative
 *
 * @author Tony Wong
 * @date 2016-08-13
 * @email 908601756@qq.com
 * @copyright Copyright © 2016 EleTeam
 * @license The MIT License (MIT)
 */

import * as types from '../actions/actionTypes';

const initialState = {
    news: [],
    isLoading: true,
    refreshing:false,
    isFirstLoaded:false,
    isFetchingMore:false,
    isMore:true,
    page:1,
    limit:10,
    total:0,
};

let newsReducer = (state = initialState, action) => {
    switch (action.type) {
        case types.kGetNewsList:
            return {
                ...state,
                isLoading: true,
                isFirstLoaded:false,
            };
            break;
        case types.kReceiveNewsList:
            return {
                ...state,
                news: action.news,
                isMore:action.isMore,
                isFirstLoaded:true,
                page:1,
            };
            break;
        case types.kGetMoreNewsList:
            return {
                ...state,
                isFetchingMore:true,
            }
            break;
        case types.kReceiveMoreNewsList:
            return {
                ...state,
                isMore:action.isMore,
                news:action.news,
                isFetchingMore:false,
                page:action.page,
            };
            break;
        case types.kFetchRefreshNewsList:
            return {
                ...state,
                refreshing:true,
            }
            break;
        case types.kRefreshNewsList:
            return {
                ...state,
                refreshing:false,
                news:action.news,
                page:1,//刷新自动回复1
            }
            break;
        default:
            return state;
    }
};

export default newsReducer;